package projectisd.client;

import java.util.List;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
/** 
 * Dit is de klas die de functies uit Les die de functies Async maakt en functies aanmaakt
 * om de array list te updaten, verwijderen en iets aan toe te voegen daaraan.
 * @author Team 2
 * @version 7.0
 */
public class LesDelegate {
    private ProjectServiceAsync projectService = GWT.create(ProjectService.class);
    LesGUI gui;
    
    void listLessen() {
    	
    	// verzamel de aanwezige lessen voor de gui
    	projectService.listLeraren(new AsyncCallback<List<Leraar>> () {
                    public void onFailure(Throwable caught) {
                    	List<Leraar> result = null;
                    	gui.service_lerarenListRetrievedFromService(result);
                    }
        
                    public void onSuccess(List<Leraar> result) {
                        gui.service_lerarenListRetrievedFromService(result);
                    }
        }//end of inner class
        );//end of listLeraren method call.    	

       	// verzamel de aanwezige muziekstukken
    	projectService.listVakken(new AsyncCallback<List<Vak>> () {
                    public void onFailure(Throwable caught) {
                    	List<Vak> result = null;
                    	gui.service_vakkenListRetrievedFromService(result);
                    }
        
                    public void onSuccess(List<Vak> result) {
                        gui.service_vakkenListRetrievedFromService(result);
                        
                    }
        }//end of inner class
        );//end of listVakken method call.    	
    	
    	projectService.listLessen(new AsyncCallback<List<Les>> () {
                    public void onFailure(Throwable caught) {
                        gui.service_eventListLessenFailed(caught);
                    }
        
                    public void onSuccess(List<Les> result) {
                        gui.service_eventListRetrievedFromService(result);
                        
                    }
        }//end of inner class
        );//end of listLes method call.
    }
    
    void addLes(final Les les) {
    	projectService.addLes(les, new AsyncCallback<Void> () {
            public void onFailure(Throwable caught) {
                gui.service_eventAddLesFailed(caught);
            }

            public void onSuccess(Void result) {
                gui.service_eventAddLesSuccessful();
            }
        }//end of inner class
        );//end of addLes method call.        
    }

    void updateLes(final Les les) {
    	projectService.updateLes(les, new AsyncCallback<Void> () {
            public void onFailure(Throwable caught) {
                gui.service_eventUpdateLesFailed(caught);
            }

            public void onSuccess(Void result) {
                gui.service_eventUpdateSuccessful();
            }
        }//end of inner class
        );//end of updateLes method call.        
    }

    void removeLes(final Les les) {
    	projectService.removeLes(les, new AsyncCallback<Void> () {
            public void onFailure(Throwable caught) {
                gui.service_eventRemoveLesFailed(caught);
            }

            public void onSuccess(Void result) {
                gui.service_eventRemoveLesSuccessful();
            }
        }//end of inner class
        );//end of updateLes method call.        
    }
    
}
